package sg.techstudio.suntec.filter;

import java.io.Serializable;

public class Paging implements Serializable{

	private static final long serialVersionUID = -969422179678136603L;
	private int firstResult, maxResults=15, page=1, maxPage=1;
	private long totalResults;
	
	public int getMaxPage() {
		return maxPage;
	}
	public void setMaxPage(int maxPage) {
		this.maxPage = maxPage;
	}
	public long getTotalResults() {
		return totalResults;
	}
	public void setTotalResults(long totalResults) {
		this.totalResults = totalResults;
		setMaxPage((int)Math.round(Math.ceil(this.totalResults/(double)maxResults)));
		setPage(page);//call again so that page is within updated max page
	}
	public int getFirstResult() {
		return firstResult;
	}
	public void setFirstResult(int firstResult) {
		this.firstResult = Math.max(0, firstResult);
	}
	public int getMaxResults() {
		return maxResults;
	}
	public void setMaxResults(int maxResults) {
		this.maxResults = Math.max(1, maxResults);
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = Math.min(maxPage, Math.max(1, page));
		setFirstResult((this.page-1)*getMaxResults());
	}
}
